<template>
	<view class="content">
		<view class="form-block" style="border-radius:30rpx 30rpx 0 0 ;">
			<view class="form-title">编辑项目经历</view>
			<view class="form-item">
				<view class="form-label">公司名称</view>
				<view class="form-content">
					<input v-model="form.companyName" placeholder="请填写公司名称" maxlength="30" type="text"
						placeholder-class="inputPlaceholder" class="form-ctrl" />
					<view class="iconfont icon-gengduo1 arrow"></view>
				</view>
			</view>
			<view class="form-item">
				<view class="form-label">项目名称</view>
				<view class="form-content">
					<input v-model="form.itemName" placeholder="请填写项目名称" maxlength="30" type="text"
						placeholder-class="inputPlaceholder" class="form-ctrl" />
					<view class="iconfont icon-gengduo1 arrow"></view>
				</view>
			</view>
			<view class="form-item">
				<view class="form-label">项目时间</view>
				<view class="form-content">
					<picker mode="date" class="form-ctrl" fields="day" :end="end" :value="form.startTime"
						@change="bindStart">
						<view class="uni-input">{{form.startTime}}</view>
					</picker>
					<picker mode="date" class="form-ctrl" fields="day" :start="form.startTime" :end="end"
						:value="form.endTime" @change="bindEnd">
						<view class="uni-input">{{form.endTime}}</view>
					</picker>
					<view class="iconfont icon-gengduo1 arrow"></view>
				</view>
			</view>
			<view class="form-item">
				<view class="form-label">项目职务</view>
				<view class="form-content">
					<input v-model="form.postName" placeholder="请填写项目职务" maxlength="30" type="text"
						placeholder-class="inputPlaceholder" class="form-ctrl" />
					<view class="iconfont icon-gengduo1 arrow"></view>
				</view>
			</view>
			<view class="form-item">
				<view class="form-label">项目描述</view>
				<view class="form-content">
					<textarea v-model="form.itemContent" :auto-height="true"
						style="line-height: normal;min-height: 300rpx;padding: 30rpx 0;" placeholder="请填写项目描述"
						maxlength="500" type="text" placeholder-class="inputPlaceholder" class="form-ctrl"></textarea>
				</view>
			</view>
			<view class="form-item">
				<view class="form-label">项目职责</view>
				<view class="form-content">
					<textarea v-model="form.itemDuty" :auto-height="true"
						style="line-height: normal;min-height: 300rpx;padding: 30rpx 0;" placeholder="请填写项目职责"
						maxlength="500" type="text" placeholder-class="inputPlaceholder" class="form-ctrl"></textarea>
				</view>
			</view>
			<view class="form-item">
				<view class="form-label">项目业绩</view>
				<view class="form-content">
					<textarea v-model="form.achievement" :auto-height="true"
						style="line-height: normal;min-height: 300rpx;padding: 30rpx 0;" placeholder="请填写项目业绩"
						maxlength="500" type="text" placeholder-class="inputPlaceholder" class="form-ctrl"></textarea>
				</view>
			</view>
			<view class="btn" @click="handleSave">保存</view>
		</view>
	</view>
</template>

<script>
	import {submitProjectExp,getItemExp} from '@/api/resume.js';
	import {
		validate
	} from '@/util/validate';
	import {
		getCurrentTime
	} from '@/util/util';
	export default {
		data() {
			return {
				end: getCurrentTime('d'),
				form: {
					companyName: '',
					itemName: '',
					startTime: getCurrentTime('d'),
					endTime: getCurrentTime('d'),
					postName: '',
					itemContent: '',
					itemDuty: '',
					achievement:'',
					id: 0
				},
				rules: {
					companyName:{
						name:'公司名称',
						required:true
					},
					itemName:{
						name:'项目名称',
						required:true
					},
					startTime:{
						name:'项目开始时间',
						required:true
					},
					endTime:{
						name:'项目结束时间',
						required:true
					},
					postName:{
						name:'项目职务',
						required:true
					},
				}
			}
		},
		methods: {
			getDetail(id) {
				uni.showLoading({
					title:'加载中',
					mask:true
				})
				getItemExp({id}).then((res)=>{
					this.form=res
				})
			},
			bindStart(e) {
				this.form.startTime = e.detail.value
			},
			bindEnd(e) {
				this.form.endTime = e.detail.value
			},
			handleSave(){
				if(this.form,this.rules){
					uni.showLoading({
						title:'提交中',
						mask:true
					})
					submitProjectExp(this.form).then(()=>{
						uni.$emit('refresh',3)
						this.showToast('保存成功',()=>{
							uni.navigateBack()
						})
					})
				}
			}
		},
		onLoad(e) {
			if (e.id) {
				this.getDetail(e.id)
			}
		}

	}
</script>

<style lang="scss">
	page {
		background: #fff;
	}

	.content {
		width: 100%;

		.btn {
			width: 350rpx;
			height: 80rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			background: #FF7626;
			color: #fff;
			font-size: 28rpx;
			border-radius: 40rpx;
			margin: 0 auto;
			margin-top: 30rpx;
		}

		.user-photo-block {
			width: 100%;
			height: 450rpx;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;

			.user-photo {
				width: 180rpx;
				height: 180rpx;
				border-radius: 50%;
			}
		}

		.form-block {
			width: 100%;
			box-shadow: 0 0 10px 0 #efefef;
			background: #fff;
			padding: 30rpx;

			.form-title {
				font-size: 36rpx;
				font-weight: bold;
			}

			.sub-title {
				font-size: 26rpx;
				color: #999;
			}

			.form-item {
				display: flex;
				flex-direction: column;
				border-bottom: 1px solid #efefef;
				padding-top: 30rpx;

				.form-label {
					font-size: 28rpx;
					color: #999;
				}

				.form-content {
					display: flex;
					flex-direction: row;
					align-items: center;

					.form-ctrl {
						height: 100rpx;
						line-height: 100rpx;
						flex-grow: 1;
					}

					.arrow {
						flex-grow: 0;
						color: #999;
						font-size: 24rpx;
					}
				}
			}
		}
	}
</style>
